// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.characters;

import zombie.ai.states.ZombieTurnAlerted;
import zombie.core.skinnedmodel.advancedanimation.IAnimatable;
import zombie.network.GameClient;
import zombie.network.GameServer;

public class NetworkZombieVariables {
    public static int getInt(IsoZombie zombie, short id) {
        switch (id) {
            case 0:
                return (int)(zombie.Health * 1000.0F);
            case 1:
                if (zombie.target == null) {
                    return -1;
                }

                return ((IAnimatable)zombie.target).getOnlineID();
            case 2:
                return (int)(zombie.speedMod * 1000.0F);
            case 3:
                return (int)zombie.TimeSinceSeenFlesh;
            case 4:
                Float _float = (Float)zombie.getStateMachineParams(ZombieTurnAlerted.instance()).get(ZombieTurnAlerted.PARAM_TARGET_ANGLE);
                if (_float == null) {
                    return 0;
                }

                return _float.intValue();
            default:
                return 0;
        }
    }

    public static void setInt(IsoZombie zombie, short id, int value) {
        switch (id) {
            case 0:
                zombie.Health = (float)value / 1000.0F;
                break;
            case 1:
                if (value == -1) {
                    zombie.setTargetSeenTime(0.0F);
                    zombie.target = null;
                } else {
                    IsoPlayer isoPlayer = (IsoPlayer)GameClient.IDToPlayerMap.get((short)value);
                    if (GameServer.bServer) {
                        isoPlayer = (IsoPlayer)GameServer.IDToPlayerMap.get((short)value);
                    }

                    if (isoPlayer != zombie.target) {
                        zombie.setTargetSeenTime(0.0F);
                        zombie.target = isoPlayer;
                    }
                }
                break;
            case 2:
                zombie.speedMod = (float)value / 1000.0F;
                break;
            case 3:
                zombie.TimeSinceSeenFlesh = (float)value;
                break;
            case 4:
                zombie.getStateMachineParams(ZombieTurnAlerted.instance()).put(ZombieTurnAlerted.PARAM_TARGET_ANGLE, (float)value);
        }
    }

    public static short getBooleanVariables(IsoZombie zombie) {
        short _short = 0;
        _short = (short)(_short | (zombie.isFakeDead() ? 1 : 0));
        _short = (short)(_short | (zombie.bLunger ? 2 : 0));
        _short = (short)(_short | (zombie.bRunning ? 4 : 0));
        _short = (short)(_short | (zombie.isCrawling() ? 8 : 0));
        _short = (short)(_short | (zombie.isSitAgainstWall() ? 16 : 0));
        _short = (short)(_short | (zombie.isReanimatedPlayer() ? 32 : 0));
        _short = (short)(_short | (zombie.isOnFire() ? 64 : 0));
        _short = (short)(_short | (zombie.isUseless() ? 128 : 0));
        return (short)(_short | (zombie.isOnFloor() ? 256 : 0));
    }

    public static void setBooleanVariables(IsoZombie zombie, short val) {
        zombie.setFakeDead((val & 1) != 0);
        zombie.bLunger = (val & 2) != 0;
        zombie.bRunning = (val & 4) != 0;
        zombie.setCrawler((val & 8) != 0);
        zombie.setSitAgainstWall((val & 16) != 0);
        zombie.setReanimatedPlayer((val & 32) != 0);
        if ((val & 64) != 0) {
            zombie.SetOnFire();
        } else {
            zombie.StopBurning();
        }

        zombie.setUseless((val & 128) != 0);
        if (zombie.isReanimatedPlayer()) {
            zombie.setOnFloor((val & 256) != 0);
        }
    }

    public static class VariablesInt {
        public static final short health = 0;
        public static final short target = 1;
        public static final short speedMod = 2;
        public static final short timeSinceSeenFlesh = 3;
        public static final short smParamTargetAngle = 4;
        public static final short MAX = 5;
    }
}
